module.exports = (sequelize, DataTypes) => {
  const SudokuAction = sequelize.define('SudokuAction', {
    id: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      autoIncrement: true,
      comment: '主键ID'
    },
    userId: {
      type: DataTypes.INTEGER,
      allowNull: false,
      field: 'user_id',  // 映射到数据库字段
      comment: '用户ID'
    },
    puzzleId: {
      type: DataTypes.INTEGER,
      allowNull: false,
      field: 'puzzle_id',  // 映射到数据库字段
      comment: '题目ID',
      references: {
        model: 'sudoku_puzzles',
        key: 'id'
      }
    },
    actionType: {
      type: DataTypes.ENUM('fill', 'erase', 'hint', 'undo'),
      allowNull: false,
      field: 'action_type',  // 映射到数据库字段
      comment: '操作类型'
    },
    cellIndex: {
      type: DataTypes.INTEGER,
      allowNull: false,
      field: 'cell_index',  // 映射到数据库字段
      comment: '操作的格子索引（0-80）'
    },
    value: {
      type: DataTypes.INTEGER,
      allowNull: true,
      comment: '填写的值（1-9）'
    },
    actionTime: {
      type: DataTypes.DATE,
      allowNull: false,
      defaultValue: DataTypes.NOW,
      field: 'action_time',  // 映射到数据库字段
      comment: '操作时间'
    },
    creator: {
      type: DataTypes.STRING(64),
      allowNull: true,
      comment: '创建人'
    },
    modifier: {
      type: DataTypes.STRING(64),
      allowNull: true,
      comment: '修改人'
    },
    isDeleted: {
      type: DataTypes.CHAR(1),
      defaultValue: '0',
      field: 'is_deleted',  // 映射到数据库字段
      comment: '是否删除（0-未删，1-已删）'
    }
  }, {
    tableName: 'sudoku_actions',
    timestamps: true,
    createdAt: 'actionTime',
    updatedAt: 'modified_at',
    indexes: [
      {
        fields: ['userId']
      },
      {
        fields: ['puzzleId']
      },
      {
        fields: ['actionType']
      },
      {
        fields: ['actionTime']
      },
      {
        fields: ['isDeleted']
      }
    ]
  });

  return SudokuAction;
};